#include <vector>
#include <fstream>
#include <iostream>

using namespace std;

vector<int> capacities; // 桶的容积
vector<int> milks;      // 桶里实际的奶的数量

void pour(int from, int to) {
  // 1. from 编号的桶里有多少牛奶
  int m = milks[from];

  // 2. to 编号的桶里还能装多少牛奶
  int n = capacities[to] - milks[to];

  int amount = min(m, n); // 实际可以倒的牛奶的数量

  milks[from] -= amount;
  milks[to] += amount;
}

int main(int argc, char const *argv[])
{
  /* code */
  // 做一些假定
  // 给每一个桶进行编号： 0 1 2

  ifstream ifs("MixMilk.in");

  for (int i = 0; i < 2; ++i) {
    int capacity = 0;
    int milk = 0;

    ifs >> capacity >> milk;
    capacities.push_back(capacity);
    milks.push_back(milk);
  }

  for (int c : capacities) {
    cout<<c<<" ";
  }
  cout<<endl;

  for (int c : milks) {
    cout<<c<<" ";
  }
  cout<<endl;

  for (int i = 0; i < 100; ++i) {
    // 0 -> 1 i = 0 pour(0, 1) => pour(0, 1)
    // 1 -> 2 i = 1 pour(1, 2) => pour(1, 2)
    // 2 -> 0 i = 2 pour(2, 3) => pour(2, 0) XXX

    //        i = 3 pour(3, 4) => pour(0, 1)
    //        i = 4 pour(4, 5) => pour(1, 2)
    //        i = 5 pour(5, 6) => pour(2, 0)

    pour(i % 3/*来源*/, (i + 1) % 3/*目标*/);
  }

  // milks 数组就是答案

  for (int milk : milks) {
    cout<< milk <<" ";
  }
  cout<<endl;

  ofstream ofs("MixMilk.out");

  ofs << milks[0] << endl << milks[1] << endl << milks[2];

  return 0;
}


